package hz.mobileproject.pda.callroll.manger;

import com.blankj.utilcode.util.SPUtils;
import com.blankj.utilcode.util.TimeUtils;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.List;

import hz.mobileproject.pda.entity.response.Response_callRoll_loadType;
import hz.mobileproject.pda.entity.response.Response_loadPrisonerList;

/**
 * Created by hasee on 2017/11/1.
 */

public class CallRollByFaceDataMgr {

    private final static String TAG = CallRollByFaceDataMgr.class.getSimpleName();

    private static CallRollByFaceDataMgr mInstance;

    /**
     * 犯人信息集合
     * 1.更新底库图片
     * 2.生成人脸集合
     * 3.视图信息展示（主要功能）
     */
    private List<Response_loadPrisonerList> mAllPrisonerList = new ArrayList<>();
    //类型集合
    private List<Response_callRoll_loadType> mLoadTypeList = new ArrayList<>();
    //条形码扫描器相关
    private int soundId;
    //机构号
    private String cusNumber;
    //nowDate
    private String nowDate;
    //警察ID
    private String policeId;
    //警察CODE
    private String policeCode;
    //警察名
    private String policeName;
    //部门ID
    private int deptId;
    //部门名
    private String deptName;
    //部门KEY
    private String deptKey;
    //点名ID
    private String recordId;
    //点名批次ID（未使用）
    private int batchCode;
    private String tempFlowKey;
    //人脸比对阈值
    private int similarityDegree;
    //点名模式  1扫码 2扫脸
    private String recognitionModel;

    private CallRollByFaceDataMgr(){
    }

    public static CallRollByFaceDataMgr getInstance(){
        if (mInstance == null){
            mInstance = new CallRollByFaceDataMgr();
        }
        return mInstance;
    }

    public CallRollByFaceDataMgr initCallRollData(){
        nowDate = TimeUtils.getNowString(new SimpleDateFormat("yyyy-MM-dd"));
        SPUtils.getInstance("Callroll_loadCnf").put("loadCnf", nowDate);
        cusNumber = SPUtils.getInstance("app_login").getString("cusnumber");
        soundId = 0;
        policeId = "";
        policeCode = "";
        policeName = "";
        deptId = 0;
        deptName = "";
        deptKey = "";
        recordId = "";
        batchCode = 0;
        mAllPrisonerList.clear();

        return mInstance;
    }

    public List<Response_callRoll_loadType> getLoadTypeList() {
        return mLoadTypeList;
    }

    public void setLoadTypeList(List<Response_callRoll_loadType> loadTypeList) {
        mLoadTypeList.clear();
        mLoadTypeList.addAll(loadTypeList);
    }

    public List<Response_loadPrisonerList> getAllPrisonerList() {
        return mAllPrisonerList;
    }

    public void setAllPrisonerList(List<Response_loadPrisonerList> allPrisonerList) {
//        mAllPrisonerList.clear();
//        mAllPrisonerList.addAll(allPrisonerList);
        mAllPrisonerList = allPrisonerList;
    }

    /**
     * 根据id删除点名集合数据
     * @param id
     */
    public synchronized void removeAllPrisonerListItem(String id) {
        for(Response_loadPrisonerList prisoner : mAllPrisonerList){
            if(prisoner.getPrisoner_id().equals(id)){
                mAllPrisonerList.remove(prisoner);
                break;
            }
        }
    }

    /**
     * 针对列表排序
     * 未点，失败，上传中，已上传
     */
    public synchronized void sortAllPrisonerList(){
        List<Response_loadPrisonerList> list0 = new ArrayList<>();
        List<Response_loadPrisonerList> list1 = new ArrayList<>();
        List<Response_loadPrisonerList> list2 = new ArrayList<>();
        List<Response_loadPrisonerList> list3 = new ArrayList<>();
        for (Response_loadPrisonerList prisoner : mAllPrisonerList){
            switch (prisoner.getCallRollStatus()){
                case 0:
                    list0.add(prisoner);
                    break;
                case 1:
                    list1.add(prisoner);
                    break;
                case 2:
                    list2.add(prisoner);
                    break;
                case 3:
                    list3.add(prisoner);
                    break;
                default:
                    break;
            }
        }
        mAllPrisonerList.clear();
        mAllPrisonerList.addAll(list0);
        mAllPrisonerList.addAll(list3);
        mAllPrisonerList.addAll(list1);
        mAllPrisonerList.addAll(list2);
    }

    /**
     * 判断是否全部点完
     * @return
     */
    public synchronized  boolean isAllCallRollSuccess(){
        for (Response_loadPrisonerList prisoner : mAllPrisonerList){
            if (prisoner.callRollStatus != 2){
                return false;
            }
        }
        return true;
    }

    /**
     * 根据id修改犯人点名状态
     * 0 未点 1比对成功，上传中 2上传成功 3上传失败
     */
    public synchronized void updateAllPrisonerListItemStatus(String id, int status) {
        for (int i=0;i<mAllPrisonerList.size();i++){
            if(mAllPrisonerList.get(i).getPrisoner_id().equals(id)){
                mAllPrisonerList.get(i).callRollStatus = status;
                break;
            }
        }
    }

    /**
     * 根据id从点名的集合中取出对应的元素
     * @param id
     * @return
     */
    public synchronized Response_loadPrisonerList getPrisonerListItemById(String id){
        for(Response_loadPrisonerList prisoner : mAllPrisonerList){
            if(prisoner.getPrisoner_id().equals(id)){
                return prisoner;
            }
        }
        return null;
    }

    public String getRecognitionModel() {
        return recognitionModel;
    }

    public void setRecognitionModel(String recognitionModel) {
        this.recognitionModel = recognitionModel;
    }
    public int getSimilarityDegree() {
        return similarityDegree;
    }

    public void setSimilarityDegree(int similarityDegree) {
        this.similarityDegree = similarityDegree;
    }
    public String getNowDate() {
        return nowDate;
    }

    public void setNowDate(String nowDate) {
        this.nowDate = nowDate;
    }

    public int getSoundId() {
        return soundId;
    }

    public void setSoundId(int soundId) {
        this.soundId = soundId;
    }

    public String getCusNumber() {
        return cusNumber;
    }

    public void setCusNumber(String cusNumber) {
        this.cusNumber = cusNumber;
    }

    public String getPoliceId() {
        return policeId;
    }

    public void setPoliceId(String policeId) {
        this.policeId = policeId;
    }

    public String getPoliceCode() {
        return policeCode;
    }

    public void setPoliceCode(String policeCode) {
        this.policeCode = policeCode;
    }

    public String getPoliceName() {
        return policeName;
    }

    public void setPoliceName(String policeName) {
        this.policeName = policeName;
    }

    public int getDeptId() {
        return deptId;
    }

    public void setDeptId(int deptId) {
        this.deptId = deptId;
    }

    public String getDeptName() {
        return deptName;
    }

    public void setDeptName(String deptName) {
        this.deptName = deptName;
    }

    public String getDeptKey() {
        return deptKey;
    }

    public void setDeptKey(String deptKey) {
        this.deptKey = deptKey;
    }

    public String getRecordId() {
        return recordId;
    }

    public void setRecordId(String recordId) {
        this.recordId = recordId;
    }

    public int getBatchCode() {
        return batchCode;
    }

    public void setBatchCode(int batchCode) {
        this.batchCode = batchCode;
    }

    public String getTempFlowKey() {
        return tempFlowKey;
    }

    public void setTempFlowKey(String tempFlowKey) {
        this.tempFlowKey = tempFlowKey;
    }
}
